using UnityEngine;

public class SystemUtil
{

    public static void SetGameObjectVisible(GameObject gameObject)
    {
        var rendererComponents = gameObject.GetComponents<Renderer>();

        foreach (var component in rendererComponents)
            component.enabled = true;
    }

    public static void SetGameObjectInVisible(GameObject gameObject)
    {
        var rendererComponents = gameObject.GetComponents<Renderer>();

        foreach (var component in rendererComponents)
            component.enabled = false;
    }

    public static void SetGameObjectChildrenVisible(GameObject gameObject)
    {
        //var canvasComponent = mParentCanvasObj.GetComponent<Canvas>(); //GetComponentInChildren
        //var canvasComponent = mParentImageTargetVideo.GetComponentInChildren<Canvas>();
        //var rendererComponents = mParentImageTargetVideo.GetComponentInChildren<Renderer>(true);

        //canvasComponent.enabled = true;
        //rendererComponents.enabled = true;


        var rendererComponents = gameObject.GetComponentsInChildren<Renderer>(true);
        var colliderComponents = gameObject.GetComponentsInChildren<Collider>(true);
        var canvasComponents = gameObject.GetComponentsInChildren<Canvas>(true);     //Canvas 下包含 VideoPlayer，需要现在 inspector 界面设置其不是禁用状态

        // Enable rendering:
        foreach (var component in rendererComponents)
            component.enabled = true;

        // Enable colliders:
        foreach (var component in colliderComponents)
            component.enabled = true;

        // Enable canvas':
        foreach (var component in canvasComponents)
            component.enabled = true;
    }


    public static void SetGameObjectChildrenInVisible(GameObject gameObject)
    {
        //var canvasComponent = mParentCanvasObj.GetComponent<Canvas>();
        //var canvasComponent = mParentImageTargetVideo.GetComponentInChildren<Canvas>();
        //canvasComponent.enabled = false;


        var rendererComponents = gameObject.GetComponentsInChildren<Renderer>(true);
        var colliderComponents = gameObject.GetComponentsInChildren<Collider>(true);
        var canvasComponents = gameObject.GetComponentsInChildren<Canvas>(true);

        // Disable rendering:
        foreach (var component in rendererComponents)
            component.enabled = false;

        // Disable colliders:
        foreach (var component in colliderComponents)
            component.enabled = false;

        // Disable canvas':
        foreach (var component in canvasComponents)
            component.enabled = false;
    }
}